<template>
  <el-menu
    class="categories"
    model="navselected"
    :default-active="this.cid"
    @select="handleSelect"
    active-text-color="red">
    <el-menu-item index="0">
      <i class="el-icon-menu"></i>
      <span slot="title">全部</span>
    </el-menu-item>
    <el-menu-item index="1">
      <i class="el-icon-menu"></i>
      <span slot="title">文学</span>
    </el-menu-item>
    <el-menu-item index="2">
      <i class="el-icon-menu"></i>
      <span slot="title">流行</span>
    </el-menu-item>
    <el-menu-item index="3">
      <i class="el-icon-menu"></i>
      <span slot="title">文化</span>
    </el-menu-item>
    <el-menu-item index="4">
      <i class="el-icon-menu"></i>
      <span slot="title">生活</span>
    </el-menu-item>
    <el-menu-item index="5">
      <i class="el-icon-menu"></i>
      <span slot="title">经管</span>
    </el-menu-item>
    <el-menu-item index="6">
      <i class="el-icon-menu"></i>
      <span slot="title">科技</span>
    </el-menu-item>
    <el-menu-item index="7">
      <i class="el-icon-menu"></i>
      <span slot="title">畅销</span>
    </el-menu-item>
    <el-menu-item index="8">
      <i class="el-icon-menu"></i>
      <span slot="title">周免</span>
    </el-menu-item>
  </el-menu>
</template>

<script>
export default {
  name: 'SideMenu',
  data () {
    return {
      cid: this.$store.state.selectMenuIndex
    }
  },
  methods: {
    handleSelect (key, keyPath) {
      // eslint-disable-next-line no-unused-vars
      var _this = this
      // eslint-disable-next-line no-undef,no-unused-expressions
      this.$store.state.selectMenuIndex = key
      this.cid = key
      console.log('改变分类:' + key + this.$store.state.selectMenuIndex + this.cid + '\n')
      // _this.$store.state.selectMenuIndex = '0'
      this.$axios.get('/library/type/' + key + '/books').then(resp => {
        if (resp && resp.status === 200) {
          console.log('改变图书列表：' + this.cid)
          this.$store.state.books = resp.data
        }
      })
    }
  }
}
</script>

<style scoped>
  .categories {
    position: fixed;
    margin-left: 50%;
    left: -650px;
    top: 115px;
    width: 150px;
  }
</style>
